package com.lanhe.weightAssistant.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanhe.common.constant.Constants;
import com.lanhe.weightAssistant.domain.LhWeightAssistant;
import com.lanhe.weightAssistant.mapper.LhWeightAssistantMapper;
import com.lanhe.weightAssistant.service.ILhWeightAssistantService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 权重助手管理(LhWeightAssistant)表服务实现类
 *
 * @author zhanggl
 * @since 2023-12-30 14:02:30
 */
@Service
public class LhWeightAssistantServiceImpl extends ServiceImpl<LhWeightAssistantMapper, LhWeightAssistant> implements ILhWeightAssistantService {

    @Resource
    private LhWeightAssistantMapper weightAssistantMapper;

    @Override
    public List<LhWeightAssistant> selectWeightAssistantList(LhWeightAssistant weightAssistant) {
        LambdaQueryWrapper<LhWeightAssistant> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LhWeightAssistant::getDelFlag, 0);
        queryWrapper.orderByDesc(LhWeightAssistant::getWeightAssistantId);
        return weightAssistantMapper.selectList(queryWrapper);
    }

    @Override
    public LhWeightAssistant selectWeightAssistantById(Long weightAssistantId) {
        LambdaQueryWrapper<LhWeightAssistant> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LhWeightAssistant::getDelFlag, 0)
                .eq(LhWeightAssistant::getWeightAssistantId, weightAssistantId);
        return  weightAssistantMapper.selectOne(queryWrapper);
    }

    @Override
    public int insertWeightAssistant(LhWeightAssistant weightAssistant) {
        return  weightAssistantMapper.insert(weightAssistant);
    }

    @Override
    public int updateWeightAssistant(LhWeightAssistant weightAssistant) {
        LambdaQueryWrapper<LhWeightAssistant> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LhWeightAssistant::getDelFlag, 0)
                .eq(LhWeightAssistant::getWeightAssistantId, weightAssistant.getWeightAssistantId());
        return weightAssistantMapper.update(weightAssistant, queryWrapper);
    }

    @Override
    public int deleteWeightAssistantByIds(Long[] assistantIds) {
        LambdaUpdateWrapper<LhWeightAssistant> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(LhWeightAssistant::getDelFlag, Constants.GeneralIntType.TWO+"")
                .in(LhWeightAssistant::getWeightAssistantId,assistantIds);
        return weightAssistantMapper.update(null,updateWrapper);
    }

    @Override
    public LhWeightAssistant getInfo() {
        LambdaQueryWrapper<LhWeightAssistant> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LhWeightAssistant::getDelFlag, 0)
                .eq(LhWeightAssistant::getWeightAssistantId, 1L);
        return  weightAssistantMapper.selectOne(queryWrapper);
    }
}

